/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bllfactory;

import bllImplement.BLLAccountImpl;
import bllImplement.BLLChatServerImpl;
import bllImplement.BLLQuerryImpl;
import bllImplement.BLLRelationImpl;
import bllInterface.*;
import bllRoom.RoomChatManagerImpl;
import java.rmi.RemoteException;
import utils.DefaultPort;
import utils.RemoteFactory;

/**
 *
 * @author salm
 */
public class BLLFactoryImpl implements BLLFactory
{
    private BLLAccount account          =   null;
    private BLLQuerry querry            =   null;
    private BLLChatServer chatServer    =   null;
    private BLLRelation relation        =   null;
    private RoomChatManager roomChatManager = null;

    @Override
    public BLLAccount getAccount() throws RemoteException
    {
        if (this.account == null)
        {
            this.account = RemoteFactory.<BLLAccount>createRemote(new BLLAccountImpl(), DefaultPort.getInstance().getBLLPort());
        }
        
        return this.account;
    }

    @Override
    public BLLQuerry getQuerry() throws RemoteException 
    {
        if( this.querry == null )
        {
            this.querry =   RemoteFactory.<BLLQuerry>createRemote(BLLQuerryImpl.getInstance(), DefaultPort.getInstance().getBLLPort());
        }
        return this.querry;
    }

    @Override
    public BLLChatServer getServerChat() throws RemoteException 
    {
        if( this.chatServer == null )
        {
            this.chatServer =  RemoteFactory.<BLLChatServer>createRemote(new BLLChatServerImpl(), DefaultPort.getInstance().getBLLPort());
        }
        return this.chatServer;
    }

    @Override
    public BLLRelation getRelation() throws RemoteException {
        if( this.relation == null )
        {
            this.relation =   RemoteFactory.<BLLRelation>createRemote(BLLRelationImpl.getInstance(), DefaultPort.getInstance().getBLLPort());
        }
        return this.relation;
    }

    @Override
    public RoomChatManager getChat() throws RemoteException
    {
        if (this.roomChatManager == null)
        {
            this.roomChatManager = RemoteFactory.<RoomChatManager>createRemote(new RoomChatManagerImpl(this.getServerChat()), DefaultPort.getInstance().getBLLPort());
        }
        
        return this.roomChatManager;
    }
}
